home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 60.zip / BS1 part 60 / Highspeed pascal.adf / HSPascal / AmigaDemos / MouseDemo.pas < prev    next >
Pascal/Delphi Source File  |  1991-12-31  |  3KB  |  84 lines

  1. {--------------------------------------------------------------------------
  2.  
  3.                      HighSpeed Pascal for the Amiga
  4.  
  5.                           MOUSE TRACKING DEMO
  6.  
  7.                   Programmed by Martin Eskildsen 1991
  8.  
  9.                   Copyright (c) 1991 by D-House I ApS
  10.                          All rights reserved
  11.  
  12.  
  13.   Version : Date (dd.mm.yy) : Comment
  14.   -----------------------------------
  15.     1.00 : 22.07.91 : First version
  16.     1.01 : 13.08.91 : Uses Init.LegalPosition
  17.     1.02 : 17.09.91 : Uses new libraries
  18.     1.03 : 06.11.91 : Final for first release
  19.  
  20. --------------------------------------------------------------------------}
  21.  
  22. program MouseDemo;
  23.  
  24. uses Init, Intuition, Exec, Graphics;
  25.  
  26. procedure DrawLoop;
  27. var
  28.   dummy    : integer;
  29.   Imessage : pIntuiMessage;   { The messages sent to this program }
  30.   class    : integer;         { Message class }
  31.   code     : integer;         { Message code }
  32.   quit     : boolean;         { TRUE = done showing menu }
  33.   drawing  : boolean;         { TRUE = we are drawing }
  34.   x, y     : integer;         { Mouse (x,y) }
  35.  
  36. begin
  37.   quit := FALSE;                       { Not done yet }
  38.   drawing := FALSE;                    { Not drawing at entry }
  39.   Move_(OutputWindow^.RPort, 2,10);    { Move to upper left of work area }
  40.   repeat
  41.     dummy := Wait(BitMask(OutputWindow^.UserPort^.MP_SIGBIT));
  42.                                         { Wait for something to happen }
  43.  
  44.     Imessage := pIntuiMessage(GetMsg(OutputWindow^.UserPort));
  45.                                         { Find out what }
  46.     while Imessage <> NIL do begin
  47.       class := Imessage^.class;         { Save for later use }
  48.       code  := Imessage^.code;
  49.       x     := Imessage^.MouseX;
  50.       y     := Imessage^.MouseY;
  51.       ReplyMsg(pMessage(Imessage));     { Accept this message }
  52.       case class of
  53.         MOUSEBUTTONS : begin
  54.                          drawing := code = SELECTDOWN;
  55.                          if drawing and LegalPosition(x, y) then
  56.                            Move_(OutputWindow^.RPort, x, y)
  57.                        end;
  58.         MOUSEMOVE    : if drawing and LegalPosition(x, y) then
  59.                          Draw(OutputWindow^.RPort, x, y);
  60.         CLOSEWINDOW_ : quit := TRUE
  61.       end;
  62.       Imessage := pIntuiMessage(GetMsg(OutputWindow^.UserPort)) { Get next }
  63.     end;
  64.   until quit
  65. end;
  66.  
  67. begin
  68.   if PrepareEnvironment('Mouse Tracking') then begin
  69.  
  70.     Message('First, a window to draw in');
  71.     with OutputWinDef do begin            { Tell Intuition that we want }
  72.       IDCMPflags := IDCMPflags or MOUSEBUTTONS or MOUSEMOVE;
  73.       Flags := Flags or REPORTMOUSE_
  74.     end;
  75.     OpenOutputWindow;
  76.  
  77.     Inform('Ready! Press left mouse button to draw; Close gadget to end');
  78.     DrawLoop;
  79.  
  80.     CloseOutputWindow;
  81.     CloseDown
  82.   end
  83. end.
  84.